const jwt = require("jsonwebtoken");
const { PRIVATE_KEY } = require("../app/config");
const connection = require("../app/database");

class AuthController {
  async login(ctx, next) {
    const { id, name } = ctx.user;
    const token = jwt.sign({ id, name }, PRIVATE_KEY, {
      expiresIn: 60 * 60 * 24 * 7,
      algorithm: "RS256",
    });
    console.log(ctx.user);
    ctx.body = {
      data: {
        user: {
          id,
          name,
          age: ctx.user.age,
          gender: ctx.user.gender,
          email: ctx.user.email,
        },
        token,
      },
      status: 200,
    };
  }
}

module.exports = new AuthController();
